package com.edu.exam.entity.grading.integration;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import com.edu.exam.enums.grading.GradingTaskStatus;

/**
 * 集成任务实体类
 *
 * <p>所属模块：B-06 成绩管理模块</p>
 * <p>对应数据库表：integration_task</p>
 *
 * <p>存储成绩数据集成任务信息</p>
 *
 * @author G-09 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class IntegrationTask {

    @Id
    @Column(name = "task_id", length = 64)
    private String taskId;

    @Column(name = "task_name", length = 255)
    private String taskName;

    @Column(name = "source_system", length = 32, nullable = false)
    private String sourceSystem;

    @Column(name = "data_type", length = 32, nullable = false)
    private String dataType;

    @Column(name = "task_status", length = 32, nullable = false)
    private String taskStatus;

    @Column(name = "priority", nullable = false)
    private Integer priority = 5;

    @Column(name = "total_count")
    private Integer totalCount;

    @Column(name = "processed_count")
    private Integer processedCount;

    @Column(name = "success_count")
    private Integer successCount;

    @Column(name = "failure_count")
    private Integer failureCount;

    @Column(name = "start_time")
    private LocalDateTime startTime;

    @Column(name = "end_time")
    private LocalDateTime endTime;

    @Column(name = "estimated_time")
    private LocalDateTime estimatedTime;

    @Column(name = "created_by", length = 64)
    private String createdBy;

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_by", length = 64)
    private String updatedBy;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @Version
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    @PrePersist
    protected void onCreate() {
        if (taskStatus == null) {
            taskStatus = "created";
        }
        if (priority == null) {
            priority = 5;
        }
        if (version == null) {
            version = 1;
        }
        if (processedCount == null) {
            processedCount = 0;
        }
        if (successCount == null) {
            successCount = 0;
        }
        if (failureCount == null) {
            failureCount = 0;
        }
    }

  
    /**
     * 数据类型枚举
     */
}
